package com.ywjh.inter.common;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.ywjh.inter.utils.StrUtil;

public class SystemConfig {

	static {
		init();
	}
	/**
	 * 数据库IP
	 */
	public static String DATABASE_URL;
	/**
	 * 数据库名
	 */
	public static String DATABASE_NAME;
	/**
	 * 数据库用户名
	 */
	public static String DATABASE_USERNAME;
	/**
	 * 数据库密码
	 */
	public static String DATABASE_PASSWORD;

	public static String CDN_DOMAIN;

	public static String MEMCACHED_IP;
	public static int MEMCACHED_PORT;

	public static void init() {
		Properties prop = new Properties();
		InputStream in = null;
		try {
			String url = "./config.properties";
			System.out.println("config:" + new File(url).getAbsolutePath());
			in = new FileInputStream(new File(url));
			prop.load(in);
			DATABASE_URL = prop.getProperty("DATABASE_URL");
			DATABASE_NAME = prop.getProperty("DATABASE_NAME");
			DATABASE_USERNAME = prop.getProperty("DATABASE_USERNAME");
			DATABASE_PASSWORD = prop.getProperty("DATABASE_PASSWORD");
			MEMCACHED_IP = prop.getProperty("MEMCACHED_IP");
			CDN_DOMAIN=prop.getProperty("CDN_DOMAIN");
			MEMCACHED_PORT = StrUtil.getInt(prop.getProperty("MEMCACHED_PORT"), 11211);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
